﻿Public Class aFUNLIST40
    Inherits System.Web.UI.Page

#Region " Web Form 設計工具產生的程式碼 "

    '此為 Web Form 設計工具所需的呼叫。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents pnlFunList As System.Web.UI.WebControls.Panel
    Protected WithEvents wtSCFunctionTree As Infragistics.WebUI.UltraWebNavigator.UltraWebTree
    Protected WithEvents wtSCAgtFunctionTree As Infragistics.WebUI.UltraWebNavigator.UltraWebTree

    '注意: 下列預留位置宣告是 Web Form 設計工具需要的項目。
    '請勿刪除或移動它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此為 Web Form 設計工具所需的方法呼叫
        '請勿使用程式碼編輯器進行修改。
        InitializeComponent()
    End Sub

#End Region

#Region " 全域變數 "
    Private mblnAgnetMode As Boolean = False
#End Region

    Dim m_strUSRID As String

    '##SUMMARY		主程式碼
    '
    '##PARAM		sender       請更改此參數說明
    '##PARAM		e       請更改此參數說明
    '
    '##RETURNS		請更改此回傳值說明
    '
    '##REMARKS		請更改此備註說明
    '
    '##VERSIONS		2004/2/27		Jupiter_Lin		New Create
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try  'Add By Code Tool
            '在這裡放置使用者程式碼以初始化網頁
            Dim strUSRID As String
            Dim strUSRCompID As String
            Dim dtScFunction As DataTable
            Dim dtScUser As DataTable
            Dim drRow As DataRow
            Dim objUser As GSS.Stirrup.Scorpio30.ScUser
            'GSS.Stirrup.Scorpio30.ScUser()
            Dim objAgent As GSS.Stirrup.Scorpio30.ScAgent


            strUSRID = GSS.Stirrup.ASPXTemplate40.GlobalVar.GSSstrUSR_ID
            m_strUSRID = strUSRID
            'GSS.Stirrup.ASPXTemplate40.GlobalVar.GSSstrUSR_ID()
            strUSRCompID = GSS.Stirrup.Scorpio30.ProcessKit.PKGlobalVar.SCstrCOMPANY_ID
            'GSS.Stirrup.ASPXTemplate40.ScorpioLibrary.SCGlobalVar.GSSstrSC_COMPANY_ID()

            If strUSRID Is Nothing Then strUSRID = "SA"
            If strUSRCompID Is Nothing Then strUSRCompID = "GSS"

            If Not IsPostBack Then
                objUser = New GSS.Stirrup.Scorpio30.ScUser(GSS.Stirrup.ASPXTemplate40.GlobalVar.GSSstrAP_CONNECT_ID)
                'GlobalVar.GSSstrAP_CONNECT_ID)
                objAgent = New GSS.Stirrup.Scorpio30.ScAgent(GSS.Stirrup.ASPXTemplate40.GlobalVar.GSSstrAP_CONNECT_ID)
                'GlobalVar.GSSstrAP_CONNECT_ID)
                If objUser.LoadUser(strUSRID, strUSRCompID) Then
                    dtScUser = objAgent.FromUsrSelAll(strUSRID, strUSRCompID)
                    If dtScUser.Rows.Count > 0 Then
                        For Each drRow In dtScUser.Rows
                            Dim tnCurrentNode As Infragistics.WebUI.UltraWebNavigator.Node
                            tnCurrentNode = New Infragistics.WebUI.UltraWebNavigator.Node
                            tnCurrentNode.DataKey = drRow("USR_ID")
                            tnCurrentNode.Text = "從 " & drRow("USR_ID") & " - " & drRow("USR_NAME") & " 代理的功能"
                            tnCurrentNode.Style.Font.Size = System.Web.UI.WebControls.FontUnit.Point(10)

                            wtSCAgtFunctionTree.Nodes.Add(tnCurrentNode)

                            dtScFunction = objUser.FunSelAllByAgent(GSS.Stirrup.ASPXTemplate40.GlobalVar.GSSstrAP_ID, "Y", "", "", "", drRow("USR_ID"), drRow("USR_COMP_ID"))
                            fnGetChildTreeNode(dtScFunction, tnCurrentNode, True, drRow("USR_ID"))
                        Next
                        wtSCAgtFunctionTree.DataKeyOnClient = True
                        wtSCAgtFunctionTree.ClientSideEvents.NodeClick = "wtSCFunctionTree_Clicked"
                        wtSCAgtFunctionTree.LeafNodeImageUrl = GSS.Stirrup.ASPXTemplate40.GlobalVar.IMG_FILE_FOLDER_PATH & "Leaf.gif"
                    End If
                    dtScFunction = objUser.FunSelAll(GSS.Stirrup.ASPXTemplate40.GlobalVar.GSSstrAP_ID, "Y", "", "", "")
                Else
                    Response.Write("Not Load User")
                End If

                ''wtSCFunctionTree.SystemImagesPath = "webctrl_client\1_0\treeimages"
                ''wtSCFunctionTree.ExpandedImageUrl = "webctrl_client\1_0\images\folderopen.gif"
                ''wtSCFunctionTree.ImageUrl = "webctrl_client\1_0\images\folder.gif"
                ''***************************************************************
                '' 以上區段為 2003 Server 所使用的程式碼
                '' 2000 Server 的 TreeView 設定如下即可
                'wtSCFunctionTree.SystemImagesPath = "..\webctrl_client\1_0\treeimages"     '此目錄內為樹狀圖的基本圖示（不包含folder與node圖示）
                'wtSCFunctionTree.ExpandedImageUrl = GlobalVar.GSSstrIMG_FILE_FOLDER_PATH & "OFolder.gif"
                'wtSCFunctionTree.ImageUrl = GlobalVar.GSSstrIMG_FILE_FOLDER_PATH & "CFolder.gif"
                ''***************************************************************
                'wtSCFunctionTree.Attributes.Item("onclick") = "Javascript:wtSCFunctionTree_Clicked();"
                ' 改用 Infragistics.WebUI.UltraWebNavigator.UltraWebTree
                ' 2004/06/04
                wtSCFunctionTree.DataKeyOnClient = True
                wtSCFunctionTree.ClientSideEvents.NodeClick = "wtSCFunctionTree_Clicked"
                wtSCFunctionTree.LeafNodeImageUrl = GSS.Stirrup.ASPXTemplate40.GlobalVar.IMG_FILE_FOLDER_PATH & "Leaf.gif"
                fnGetChildTreeNode(dtScFunction, wtSCFunctionTree)


                '----customize by Scorpio Team Member
                '----設定pnlFunList在頁面上的位置
                pnlFunList.Attributes.Add("style", "position:absolute;left:10;top:30;")
            End If

        Catch ex As Exception

            GSS.Stirrup.BaseService10.Toolkit.LogWriter.Write(ex, " sender=" & "..." & ", e=" & "...")
            Throw ex
        End Try
    End Sub

    '##SUMMARY		做Treenode的遞迴
    '
    '##PARAM		vdtScFunction       傳入的datatable
    '##PARAM		vtnParentNode       父系的treenode
    '
    '##RETURNS		請更改此回傳值說明
    '
    '##REMARKS		請更改此備註說明
    '
    '##VERSIONS		2004/2/27		Jupiter_Lin		New Create
    Sub fnGetChildTreeNode(ByVal vdtScFunction As DataTable, ByVal vtnParentNode As Object, Optional ByVal vblnAgtTree As Boolean = False, Optional ByVal vstrFROM_USR_ID As String = "")
        Try  'Add By Code Tool
            Dim dvMyFunction As DataTable
            Dim dvScFunction As DataView
            Dim tnCurrentNode As Infragistics.WebUI.UltraWebNavigator.Node
            Dim i As Integer
            Dim strHref As String
            Dim strAgent As String
            Dim strFunID As String
            Dim strFunName As String
            Dim strFunAPID As String
            Dim strTarget As String


            dvMyFunction = vdtScFunction.Copy
            dvScFunction = dvMyFunction.DefaultView
            If TypeOf (vtnParentNode) Is Infragistics.WebUI.UltraWebNavigator.UltraWebTree Or vblnAgtTree Then
                dvScFunction.RowFilter = "PARENT_FUN_ITEM_ID ='' or PARENT_FUN_ITEM_ID is NULL"
                mblnAgnetMode = vblnAgtTree
            Else
                dvScFunction.RowFilter = "PARENT_FUN_ITEM_ID='" & vtnParentNode.DataKey & "'"
            End If

            dvScFunction.Sort = "FUN_SORT_ORDER,FUN_ITEM_ID"

            '計算總node數，先marl起來
            'intNodeCount = intNodeCount + dvScFunction.Count
            If dvScFunction.Count = 0 Then
                If wtSCFunctionTree.Nodes.Count = 0 Then Exit Sub
                vtnParentNode.Style.Cursor = Infragistics.WebUI.[Shared].Cursors.Hand
                Exit Sub
            Else

                Dim strTemp As String

                For i = 0 To dvScFunction.Count - 1
                    tnCurrentNode = New Infragistics.WebUI.UltraWebNavigator.Node
                    tnCurrentNode.DataKey = dvScFunction.Item(i).Item("FUN_ITEM_ID")
                    tnCurrentNode.Text = dvScFunction.Item(i).Item("FUN_ITEM_NAME")
                    tnCurrentNode.Style.Font.Size = System.Web.UI.WebControls.FontUnit.Point(10)

                    strHref = GetAttribute(dvScFunction.Item(i).Item("PRG_PATH"))

                    If mblnAgnetMode Then
                        strAgent = "1"
                    Else
                        strAgent = "0"
                    End If
                    strFunID = GetAttribute(dvScFunction.Item(i).Item("FUN_ITEM_ID"))
                    strFunName = GetAttribute(dvScFunction.Item(i).Item("FUN_ITEM_NAME"))
                    strFunAPID = GetAttribute(dvScFunction.Item(i).Item("AP_ID"))
                    strTarget = "main"
                    If strHref = "" Then
                        Page.RegisterHiddenField("tn" & dvScFunction.Item(i).Item("FUN_ITEM_ID"), "OpenTreeNode")
                    Else

                        If strHref.IndexOf("UserID=") >= 0 Then

                            strTemp = strHref.Replace("UserID=", "UserID=" & m_strUSRID)

                            Page.RegisterHiddenField("tn" & dvScFunction.Item(i).Item("FUN_ITEM_ID"), "funExpand('" & strTemp & "','" & strAgent & "','" & vstrFROM_USR_ID & "','" & strFunID & "','" & strFunName & "','" & strFunAPID & "','" & strTarget & "')")

                        Else
                            Page.RegisterHiddenField("tn" & dvScFunction.Item(i).Item("FUN_ITEM_ID"), "funExpand('" & strHref & "','" & strAgent & "','" & vstrFROM_USR_ID & "','" & strFunID & "','" & strFunName & "','" & strFunAPID & "','" & strTarget & "')")

                        End If

                        'Page.RegisterHiddenField("tn" & dvScFunction.Item(i).Item("FUN_ITEM_ID"), "funExpand('" & strHref & "','" & strAgent & "','" & vstrFROM_USR_ID & "','" & strFunID & "','" & strFunName & "','" & strFunAPID & "','" & strTarget & "')")
                    End If

                    vtnParentNode.Nodes.Add(tnCurrentNode)
                    If mblnAgnetMode Then
                        fnGetChildTreeNode(vdtScFunction, tnCurrentNode, , vstrFROM_USR_ID)
                    Else
                        fnGetChildTreeNode(vdtScFunction, tnCurrentNode)
                    End If

                Next

            End If

        Catch ex As Exception

            GSS.Stirrup.BaseService10.Toolkit.LogWriter.Write(ex, " vdtScFunction=" & "..." & ", vtnParentNode=" & "...")
            Throw ex
        End Try
    End Sub

    '##SUMMARY		處理資料為Null跟""的問題
    '
    '##PARAM		vobj       請更改此參數說明
    '
    '##RETURNS		請更改此回傳值說明
    '
    '##REMARKS		請更改此備註說明
    '
    '##VERSIONS		2004/2/27		Jupiter_Lin		New Create
    Function GetAttribute(ByVal vobj As Object) As Object
        Try  'Add By Code Tool
            If vobj Is DBNull.Value Then
                Return ""
            Else
                Return vobj
            End If

        Catch ex As Exception
            GSS.Stirrup.BaseService10.Toolkit.LogWriter.Write(ex, " vobj=" & "...")
            Throw ex
        End Try
    End Function
End Class
